package com.strawcom.charmring.imagebrowser;

import java.util.List;

import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;

import com.bumptech.glide.Glide;
import com.example.photoview.HackyViewPager;
import com.example.photoview.photoview.PhotoView;
import com.strawcom.charmring.BaseActivity;
import com.strawcom.charmring.R;
import com.strawcom.charmring.util.AnimUtil;

public class ShowImageActivity extends BaseActivity {

	private List<String> list;
	private ViewPager mViewPager;
	
    @Override
	public void onCreate(Bundle savedInstanceState) {
    	setContentView(R.layout.activity_show_image);
		super.onCreate(savedInstanceState);
		
		final View backView = findViewById(R.id.layout_left);
		backView.setOnClickListener(new View.OnClickListener() {
			@Override public void onClick(View v) {
				backView.startAnimation(AnimUtil.init().addAlpha(1f, 0f, 0, 300, new LinearInterpolator(), Animation.REVERSE).create());
				onBackPressed();
			}
		});
		
		
        mViewPager = (HackyViewPager) findViewById(R.id.view_pager);
		
		list = getIntent().getStringArrayListExtra("list");
		mViewPager.setAdapter(adapter);
		
		int poistion=getIntent().getIntExtra("poistion", 0);
		mViewPager.setCurrentItem(poistion);
		adapter.notifyDataSetChanged();
	}

    public PagerAdapter adapter= new PagerAdapter() {


		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public View instantiateItem(ViewGroup container, int position) {
			PhotoView photoView = new PhotoView(container.getContext());
			Glide.with(ShowImageActivity.this).load(list.get(position)).into(photoView);
//			photoView.setTag(position);
			container.addView(photoView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

			return photoView;
		}

		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			container.removeView((View) object);
		}

		@Override
		public boolean isViewFromObject(View view, Object object) {
			return view == object;
		}

	};

}
